package com.ds.lens.data.service.dao.sql.provider;

import com.ds.lens.data.service.dao.entity.LensScheduleDowntime;
import org.apache.ibatis.jdbc.SQL;

public class LensScheduleDowntimeSqlProvider {

    public String insertSelective(LensScheduleDowntime record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("lens_schedule_downtime");

        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getApplicationId() != null) {
            sql.VALUES("application_id", "#{applicationId,jdbcType=BIGINT}");
        }

        if (record.getState() != null) {
            sql.VALUES("state", "#{state,jdbcType=TINYINT}");
        }

        if (record.getMonitorId() != null) {
            sql.VALUES("monitor_id", "#{monitorId,jdbcType=BIGINT}");
        }

        if (record.getMonitorName() != null) {
            sql.VALUES("monitor_name", "#{monitorName,jdbcType=VARCHAR}");
        }

        if (record.getMonitorTags() != null) {
            sql.VALUES("monitor_tags", "#{monitorTags,jdbcType=VARCHAR}");
        }

        if (record.getScheduleType() != null) {
            sql.VALUES("schedule_type", "#{scheduleType,jdbcType=TINYINT}");
        }

        if (record.getStartTime() != null) {
            sql.VALUES("start_time", "#{startTime,jdbcType=TIMESTAMP}");
        }

        if (record.getEndTime() != null) {
            sql.VALUES("end_time", "#{endTime,jdbcType=TIMESTAMP}");
        }

        if (record.getRecurringContent() != null) {
            sql.VALUES("recurring_content", "#{recurringContent,jdbcType=VARCHAR}");
        }

        if (record.getCreator() != null) {
            sql.VALUES("creator", "#{creator,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.VALUES("mender", "#{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.VALUES("modified_time", "#{modifiedTime,jdbcType=TIMESTAMP}");
        }

        if (record.getIsDelete() != null) {
            sql.VALUES("is_delete", "#{isDelete,jdbcType=BIT}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(LensScheduleDowntime record) {
        SQL sql = new SQL();
        sql.UPDATE("lens_schedule_downtime");

        if (record.getApplicationId() != null) {
            sql.SET("application_id = #{applicationId,jdbcType=BIGINT}");
        }

        if (record.getState() != null) {
            sql.SET("state = #{state,jdbcType=TINYINT}");
        }

        if (record.getMonitorId() != null) {
            sql.SET("monitor_id = #{monitorId,jdbcType=BIGINT}");
        }

        if (record.getMonitorName() != null) {
            sql.SET("monitor_name = #{monitorName,jdbcType=VARCHAR}");
        }

        if (record.getMonitorTags() != null) {
            sql.SET("monitor_tags = #{monitorTags,jdbcType=VARCHAR}");
        }

        if (record.getScheduleType() != null) {
            sql.SET("schedule_type = #{scheduleType,jdbcType=TINYINT}");
        }

        if (record.getStartTime() != null) {
            sql.SET("start_time = #{startTime,jdbcType=TIMESTAMP}");
        }

        if (record.getEndTime() != null) {
            sql.SET("end_time = #{endTime,jdbcType=TIMESTAMP}");
        }

        if (record.getRecurringContent() != null) {
            sql.SET("recurring_content = #{recurringContent,jdbcType=VARCHAR}");
        }

        if (record.getCreator() != null) {
            sql.SET("creator = #{creator,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.SET("mender = #{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.SET("modified_time = #{modifiedTime,jdbcType=TIMESTAMP}");
        }

        if (record.getIsDelete() != null) {
            sql.SET("is_delete = #{isDelete,jdbcType=BIT}");
        }

        sql.WHERE("id = #{id,jdbcType=BIGINT} and state = 1 and is_delete = 0");

        return sql.toString();
    }
}
